package in.muton.edushare.url;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.pages.coursepages.CourseFolder;
import in.muton.edushare.pages.deptpages.DeptFolders;
import in.muton.edushare.pages.folder.FolderHelper;
import in.muton.edushare.pages.group.GroupFolder;
import in.muton.edushare.pages.univ.UnivFolders;
import in.muton.edushare.pages.user.UserFolders;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

import com.edushare.common.dao.FileDirectoriesDAO;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.FileDirectories;
import com.edushare.common.vo.Groups;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.Users;
import com.edushare.common.vo.interfaces.IFileUploadable;

public class FolderURLPanel extends Panel {

	public FolderURLPanel(String id, IModel<FileDirectories> model) {
		super(id, model);
		IFileUploadable owner = new FileDirectoriesDAO(EduShareSession.get().getSessionORMInterface())
									.getOwnerObject(model.getObject());
		Class<? extends WebPage> folderClass = null;
		if(owner instanceof Universities){
			folderClass = UnivFolders.class;
		}else if(owner instanceof Departments){
			folderClass = DeptFolders.class;
		}else if(owner instanceof CourseInstances){
			folderClass = CourseFolder.class;
		}else if(owner instanceof Users){
			folderClass = UserFolders.class;
		}else if(owner instanceof Groups){
			folderClass = GroupFolder.class;
		}
		
		AbstractLink link;
		if(folderClass != null){
			link = 
				new BookmarkablePageLink<Void>("url", folderClass, FolderHelper.getDirectoryPageParameters(model.getObject()));
		}else{
			link = new ExternalLink("url", "#");
		}
		
		link.add(new Label("txt",model.getObject().getDirectoryName()));
		add(link);
	}
	
}
